
<template>

  <div class="bg-f5f5f5 " >
     
      <div class="home-bar page-bar position-fixed " >
        
        <!--<div class="color-ffffff display-inline-block position-absolute title-left font-size-14" >
          退出
        </div>
        <div class="color-ffffff display-inline-block text-align-center home-title" style="width:100%;">
            家庭医生
        </div>
      <div class="color-ffffff display-inline-block position-absolute title-right font-size-13" >
          历史记录
        </div>-->
        <mt-header v-if="!tabsClickBoolean" title="家庭医生">
        <!--<router-link to="/" slot="left">s
          <mt-button icon="back">退出</mt-button>
        </router-link>-->
       <!--<router-link  slot="right" @click="stateGohomeHistory()"   style="text-decoration:none;"> 历史记录</router-link> to="/homeHistory"-->
     <!--<mt-button slot="right" @click="stateGohomeHistory()" >历史记录</mt-button>-->
      
      </mt-header>

       <mt-header v-if="tabsClickBoolean"  title="新消息">
       </mt-header>

      
      </div>
   

    <div class="height-56"></div>
                  
                  <!--家庭医生-->
                  <div v-if="!tabsClickBoolean"  >
                  <!--<mt-loadmore :top-method="loadTop(true)"  ref="loadmore1">-->
                  <div  class="home-list bg-ffffff " v-for="item in homeListDoctorArr1" @click="stateGoHomeDetails(item)">
                      <div class=" width100">
                              <div class="display-inline-block list-left position-relative home-list-img-div overflow-hidden">
                                  <!--<img   v-bind:src='item.photo_url!=""?homeListDoctorArr1Img+item.photo_url:homeListDoctorSpare'  :onerror="SpareImg()" class=" home-list-img">-->
                                  <!--<img  src='../assets/houyangna.png' class=" home-list-img">-->
                                  <!--图片用懒加载-->
                                  <img    v-lazy='item.photo_url!=""?homeListDoctorArr1Img+item.photo_url:""'   class=" home-list-img" style="padding:8px 0 0 0;">
                                  
                            </div>
                            <div class="display-inline-block position-relative list-right home-list-img-div float-right" >
                                  <div class="font-size-13" style="text-align:left;width:82%;margin-top:12px;;">
                                      <div class="color-333333 display-inline-block">{{item.name}}</div>
                                      
                                       <div class="color-888888 display-inline-block">{{item.position==''?'':item.position}}</div>  
                                      
                                      <div class="color-888888 ">{{item.tel==''?'':'电话:'+item.tel}}</div>
                            </div>

                                  <div class="position-absolute font-size-13 color-666666" style="right:0;top:20px;">{{item.title?item.title:''}}</div>
                            </div>
                    </div>
                  </div>
                  <!--</mt-loadmore>-->
                  </div>
                    <div v-if="tabsClickBoolean==false?homeListDoctorArr1.length==0:false" @click="RefreshHomeList()" class="color-888888 text-align-center" style="margin:20% 0;">暂无内容 点击刷新</div>
                  



                  <!--新消息-->
                  <div v-if="tabsClickBoolean">
                      <div  v-for="item in NewNewsArrSessionStorageArr" @click="stateGohomeDetailsDialogBox(item)">
                        <div class="home-list bg-ffffff overflow-hidden "  style="margin:4px 0;">
                            <div class=" width100">
                                    <div class="display-inline-block list-left position-relative home-list-img-div">
                                        <!--<img  v-bind:src="doctorImg(item)"  :onerror="SpareImg()" class=" home-list-img">-->
                                        <!--图片用懒加载-->
                                        <img   v-lazy="doctorImg(item)" style="padding:8px 0 0 0;"  class=" home-list-img">
                                        
                                  </div>
                                  <div class="display-inline-block position-relative list-right home-list-img-div float-right" >
                                        <div class="font-size-13" style="text-align:left;width:82%;margin-top:12px;;">
                                            <div class="color-333333">{{item.name}}</div>
                                            <div class="color-888888 overflow-hidden text1-hide"  style="width:130px;">{{item.content}}</div>
                                  </div>

                                        <div class="position-absolute font-size-13 color-666666" style="right:0;top:20px;">{{item.time}}</div>
                                  </div>
                          </div>
                        
                        </div>
                        <div style="height:2px;"></div>
                      </div>  
                  </div>

                   <div v-if="tabsClickBoolean==true?NewNewsArrSessionStorageArr.length==0:false" @click="RefreshHomeList1()" class="color-888888 text-align-center" style="margin:20% 0;">暂无消息 点击刷新</div>
                  
                  
                  <div style="height:3.6rem"></div>
                   <!--底部tabs 按键-->
                  <div class="position-fixed " style="width:100%;height:3rem;background:#fff;bottom:0;">
                  <div style="height:0.5rem"></div>
                  <div class="position-relative" style="width:96%;height:42px;margin:0 auto;">
                      
                    
                       <div class="display-inline-block" style="width:49%;">
                          <mt-button  v-if="!tabsClickBoolean" type="default" @click="tabsClick(true)" size="small" class="width100" >新消息</mt-button>
                          <mt-button  v-if="tabsClickBoolean" type="primary" @click="tabsClick(true)"  size="small" class="width100" >新消息</mt-button>
                       </div>
                        <div class="display-inline-block" style="width:49%;">
                         <mt-button  v-if="tabsClickBoolean" type="default" @click="tabsClick(false)" size="small" class="width100" >家庭医生</mt-button>
                         <mt-button  v-if="!tabsClickBoolean" type="primary" @click="tabsClick(false)"  size="small" class="width100" >家庭医生</mt-button>
                       </div>
                      
                  </div>
                 
                  </div>
                  
                
  </div>
  
 
</template>

<script>

import { Header,Button,Lazyload,Loadmore,Indicator   } from 'mint-ui';

import Vue from 'vue';
import AppVue from '../App';

import config from '../config/config.js';
import  http from '../config/http.js';

Vue.component(Header.name, Header,Button,Lazyload,Loadmore.name, Loadmore);



export default {
  name: 'home',
  data () {
    return {
 msg: 'home',
      //当前设备的高度
 currentEquipmentHeight:config.currentEquipmentHeight-56-25,
     
     
 //按照人家的需求 医生名字改动(取消)
 homeListDoctorArr:[
		],
  //医生列表
  homeListDoctorArr1:[],
  //医生列表 图片前缀
  homeListDoctorArr1Img:config.ObtainDoctorListDoctorImgSplicing,
  //备用医生头像(无用)
  homeListDoctorSpare:require('../assets/yisheng.png'),
  //点击那个tabs true家庭医生 还是 false新消息
  tabsClickBoolean:JSON.parse(sessionStorage.getItem("tabsClickBoolean"))!=null?(JSON.parse(sessionStorage.getItem("tabsClickBoolean"))):true,


  //新消息
  NewNewsArrSessionStorageArr:JSON.parse(sessionStorage.getItem("NewNewsArrSessionStorage"))?JSON.parse(sessionStorage.getItem("NewNewsArrSessionStorage")):'',
  
  
  //接受传值
  WeChatNoticeStateGoJudgeRouterParams:'',
  
  }
  },
   mounted(){
      //判断是从微信公众号跳过来的 还是微信通知跳过来的=>(微信通知跳过来的 直接跳转到对话框)
      this.WeChatNoticeStateGoJudgeRouterParams = this.$route.params.LoginObj;
      console.log(this.WeChatNoticeStateGoJudgeRouterParams);
      //this.WeChatNoticeStateGoJudgeRouterParams!=undefined
     
      
      
     
      //sessionStorage.removeItem('homeDetailsVal');////不删除  IOS端的微信内置浏览器可以前进
      AppVue.methods.NewNews();
      this.uuidObtainDoctorList();

      

     

       
      // console.log('test')
      // console.log(this.$route.path)
      //console.log(JSON.parse(sessionStorage.getItem("tabsClickBoolean")))
   },
   //销毁完成状态
   destroyed(){
     config.scrollTopFunName(); 
   
   },
   methods:{

     
       //跳转历史记录
      stateGohomeHistory(){
            // if(config.isIosPlatform==false){
            //安卓
             this.$router.push({ path: '/homeHistory',name:'homeHistory',params:{}});
             //this.$router.replace({ path: '/homeHistory',name:'homeHistory',params:{}});  
          // }else{
            //ios
              //this.$router.replace({ path: '/homeHistory',});
          // } 
      },
      

      //跳转详情
      stateGoHomeDetails(item){
           console.log(config.isIosPlatform)
        
             sessionStorage.removeItem('homeDetailsVal');//不删除  IOS端的微信内置浏览器可以前进
             this.$router.push({ path: '/homeDetails',name:'homeDetails',params:{itemObj:item}});
             //this.$router.replace({ path: '/homeDetails',name:'homeDetails',params:{itemObj:item}});  
         
      },
      //家庭医生 点击 暂无内容 刷新
      RefreshHomeList(){
            this.uuidObtainDoctorList();
      },
      //新消息 点击暂无内容 刷新
      RefreshHomeList1(){
            this.ObtainNewNewsArrSessionStorageArr();
      },  

      

      //获取当前uuid 对应的医生列表
      uuidObtainDoctorList(){
             if(this.WeChatNoticeStateGoJudgeRouterParams!=undefined && this.WeChatNoticeStateGoJudgeRouterParams.WeChatAlertTips!=''){
                Indicator.open({
                  text: '加载中...',
                  spinnerType: 'fading-circle'
                });
             }  
                         
            
             let uuidObtainDoctorListObj={
                  loc:'t',//峰哥发的自带
                  op:'queryNewSignByUuid',//峰哥发的自带 //旧的querySignByUuid 新queryNewSignByUuid
                  UUID:(JSON.parse(localStorage.getItem("loginStorageLocalStorage"))).id,//本地储存的uuid userid 部署的时候用
                  //UUID:JSON.parse(sessionStorage.getItem("userid")),//测试用的//'91330e15def74fafa81ed6fd663abe07',//91330e15def74fafa81ed6fd663abe07  d7d1b0a738424a6594cb720977a24677
                  
             }
             http.get(config.ObtainDoctorList,uuidObtainDoctorListObj)
            .then((value)=>{
                //console.log(JSON.parse(value.data.rows[0].listData)) 
                Indicator.close();  
                if(value.success==true || value.message=='获取成功'){

                 
                   if(value.data.rows.length==0){
                     
                           this.homeListDoctorArr1=[];
                       
                       
                   }else{   
                        //this.homeListDoctorArr1=JSON.parse(value.data.rows[0].listData);
                        //this.homeListDoctorArr1=JSON.parse(value.data.rows[0].list);
                        this.homeListDoctorArr1=value.data.rows[0].list;
                        console.log('___233');
                        console.log(this.homeListDoctorArr1);
                        if(this.WeChatNoticeStateGoJudgeRouterParams!=undefined && this.WeChatNoticeStateGoJudgeRouterParams.WeChatAlertTips!=''){
                          
                          //微信通知 跳转对话框
                          this.$router.push({ path: '/homeDetailsDialogBox',name:'homeDetailsDialogBox',params:{itemObj:{
                              content:'...',
                              id:this.WeChatNoticeStateGoJudgeRouterParams.doctorId,
                              id_no:'',
                              name:decodeURI(this.WeChatNoticeStateGoJudgeRouterParams.doctorName),
                              time:'',
                          }}});  
                          }
                        //储存首页list 列表 因为二级三级页面没有数据 
                        window.sessionStorage.setItem("homeListDoctorArr1",JSON.stringify( this.homeListDoctorArr1));
                         
                   }
                  this.ObtainNewNewsArrSessionStorageArr();
                   }else{  
                     Toast({
                      message: '获取医生列表失败',
                      position: 'bottom',
                      duration: 2000
                    });
                }
                
            },(error)=>{
                console.log('error');
                Indicator.close();
                Toast({
                message: '获取医生列表失败',
                position: 'bottom',
                duration: 2000
              });
                
            })
      },
      //img onerror (无用)
      SpareImg(){
          return 'this.src="' + require('../assets/yisheng.png') + '"';
          
      },
      tabsClick(Boolean){
        //console.log(Boolean)
        this.tabsClickBoolean=Boolean;

        //调用父级方法 获取新消息
        if(this.tabsClickBoolean==false){
          
           
           //记录返回时应该在那个页面
           window.sessionStorage.setItem("tabsClickBoolean",JSON.stringify(Boolean));
        }else{
         
          window.sessionStorage.setItem("tabsClickBoolean",JSON.stringify(Boolean));
        }
       
      },



      //新消息逻辑/////////////////////
       doctorImg(str){
      
        let homeListDoctorArr1Storage=(JSON.parse(sessionStorage.getItem("homeListDoctorArr1")));
        for(let i in homeListDoctorArr1Storage){
            if(homeListDoctorArr1Storage[i].member_id==str.id){
                 return config.ObtainDoctorListDoctorImgSplicing+homeListDoctorArr1Storage[i].photo_url;
            }
        }
        
      },
      //跳转=> 对话框
      stateGohomeDetailsDialogBox(item){
           
            //if(config.isIosPlatform==false){ 
            //安卓
            this.$router.push({ path: '/homeDetailsDialogBox',name:'homeDetailsDialogBox',params:{itemObj:item}});
           //}else{
            //ios
            //  this.$router.replace({ path: '/homeDetailsDialogBox',name:'homeDetailsDialogBox',params:{itemObj:item}});
           //}  

           //为了兼容IOS端的微信浏览器 只能用储存标记 在医生列表详情点击时 清除
           window.sessionStorage.setItem("NewNewsArrSessionStorageSign",JSON.stringify(item));
           
      },
      //新消息获得
      ObtainNewNewsArrSessionStorageArr(){
          if(JSON.parse(sessionStorage.getItem("NewNewsArrSessionStorage"))){
               this.NewNewsArrSessionStorageArr=JSON.parse(sessionStorage.getItem("NewNewsArrSessionStorage"));
          } 
         
          
                    
      },

     //下拉刷新(取消或未完工)
     loadTop(Boolean){
        //this.$refs.loadmore1.onTopLoaded();//下拉刷新收回
       if(Boolean==true){
       //家庭医生
       
       }else{
       //新消息
       
       }
         
         
     },
      

     
   },
    props:{
          //父级传过来的值
          OverallSituation:'',
    },
    watch:{
        OverallSituation(curVal,oldVal){
            console.log('监听');
            console.log(curVal);
            if(curVal.length){
                if(curVal.length!=0){
                //新消息列表用事实消息生成新消息列表
                let newSarr=[];
                let UUId=(JSON.parse(localStorage.getItem("loginStorageLocalStorage"))).id;
                for(var z in curVal){
                   if(curVal[z].length!=0){
                      if(curVal[z][0].sendId!=UUId){
                            newSarr.push({
                              id:curVal[z][0].sendId,
                              name:curVal[z][0].sendName,
                              content:curVal[z][0].content,
                              id_no:'',
                              time:curVal[z][0].createDate,
                           })
                      }else if(curVal[z][0].toId!=UUId){
                            newSarr.push({
                              id:curVal[z][0].toId,
                              name:curVal[z][0].toName,
                              content:curVal[z][0].content,
                              id_no:'',
                              time:curVal[z][0].createDate,
                           })
                      }
                      
                   }
                }
                
                //储存最新列表 
                  console.log(newSarr);
                  this.NewNewsArrSessionStorageArr=newSarr;
                  window.sessionStorage.setItem("NewNewsArrSessionStorageSign",JSON.stringify(newSarr));
                this.ObtainNewNewsArrSessionStorageArr();
                }else{
                    console.log('无变化')
                }        
            }
            
            // console.log(oldVal);
        },
      
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    .home-title{
        font-size:19px;
        margin-top:16px;
    }
    .title-left{
        left:6px;
        top:18px;
        
    }
    .title-right{
        right:6px;
        top:18px;
        
    }
    .home-list{
      height:60px;
      border-bottom:1px solid #ddd;
      padding:4px 12px;
    }
    .list-left{
      width:18%;
    }

    .list-right{
      width:80%;
    }
    
    
    .home-list-img-div{
      height:60px;
      text-align:center;
     
     
      
    }
    .home-list-img{
        width:50px;
         margin-top:0px;
    }
   .mint-header{
  height:56px;
   background: -webkit-linear-gradient(left, #1de5e2, #b588f7) !important;
   
}
 /*lazy 懒加载图片404的时候*/
 img[lazy=error] {
    background:url('../assets/yisheng.png');
    background-size:50px auto;
    background-repeat:no-repeat;
  }

</style>
